#include "firstrun.h"
#include "ui_firstrun.h"
#include "widget.h"

#include <QFileDialog>
#include <QDebug>
#include <QSettings>

firstRun::firstRun(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::firstRun)
{
    ui->setupUi(this);
    ui->buttonBox->button(QDialogButtonBox::Save)->setText(tr("保存"));
    ui->buttonBox->button(QDialogButtonBox::Cancel)->setText(tr("取消"));

    if (true == QFile::exists(QDir::currentPath() + "/config.ini"))
    {
        QSettings *configIniRead = new QSettings("config.ini", QSettings::IniFormat);
        QString path = configIniRead->value("/Workspace/Path").toString();
        ui->lineEdit_workpath->setText(path);
        delete configIniRead;
    }
}

firstRun::~firstRun()
{
    delete ui;
}

void firstRun::on_pButton_workpath_clicked()
{
    QString file_path = QFileDialog::getExistingDirectory(this, "请选择工作区路径...", "./");
    if (file_path.isEmpty())
    {
        return;
    }
    else
    {
        qDebug() << file_path << endl;
        ui->lineEdit_workpath->setText(file_path);
    }
}

void firstRun::on_firstRun_accepted()
{
    QSettings *configIniWrite = new QSettings("config.ini", QSettings::IniFormat);

    configIniWrite->setValue("/Workspace/Path", ui->lineEdit_workpath->text());
    configIniWrite->setValue("/Workspace/Remember", ui->checkBox_rem->isChecked());

    delete configIniWrite;
}
